import java.util.Scanner;

public class addbook implements doOperation{
    @Override
    public void work(booklist bl) {
        int currentSize= bl.getUsedsize();
        if(currentSize==bl.getBooks().length){
            System.out.println("书架满了，无法放置");
            return;
        }
        Scanner p=new Scanner(System.in);
        System.out.println("请输入您要添加的书名");
        String name=p.nextLine();
        for(int i=0;i< bl.getUsedsize();i++){
            book a=bl.getbook(i);
            if(a.getName().equals(name)) {
                System.out.println("已经有这本书了，不能重复添加");
                return;
            }
        }
        System.out.println("请输入书本的作者");
        String author=p.nextLine();
        System.out.println("请输入书的价格");
        int price=p.nextInt();
        p.nextLine();
        System.out.println("请输入书的类别");
        String type=p.nextLine();
       book newbook=new book(name,author,price,type);
       bl.setbook(currentSize,newbook);
       bl.setUsedsize(currentSize+1);
    }
}
